//
//  DRGradedViewController.m
//  DoctorRen
//
//  Created by Macx on 2018/12/8.
//

#import "DRGradedViewController.h"
#import "DRGradedCell.h"
#import "DRMineDataModel.h"

@interface DRGradedViewController ()<UITableViewDelegate ,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (nonatomic, assign) NSInteger currentIndex;

@property (weak, nonatomic) IBOutlet UIView *contentView;

@end

@implementation DRGradedViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.contentView.layer.cornerRadius = 5;
    self.contentView.layer.masksToBounds = YES;
    self.tableView.bounces = NO;
    self.currentIndex = 0;
    [self.tableView reloadData];
}

-(NSArray *)titles {
    return @[
             @"很好(5分)",
             @"好(4分)",
             @"一般(3分)",
             @"差(2分)",
             @"较差(1分)"
             ];
}
- (IBAction)clickCancel:(id)sender {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (IBAction)clickOK:(id)sender {
    [SVProgressHUD showWithStatus:@"正在提交评分"];
    [DRMineDataModel submitScore:5 - self.currentIndex success:^{
        [SVProgressHUD showSuccessWithStatus:@"评分成功"];
        [self dismissViewControllerAnimated:YES completion:nil];
    } andFail:^(NSError *error) {
        [SVProgressHUD showErrorWithStatus:error.localizedDescription];
    }];
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [self titles].count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 40;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DRGradedCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DRGradedCell" forIndexPath:indexPath];
    cell.titleLB.text = [self titles][indexPath.row];
    [cell.iconIV setHidden:indexPath.row != self.currentIndex];
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    self.currentIndex = indexPath.row;
    [self.tableView reloadData];
}

@end
